package com.ah.http.httpsclient.demo;

import com.ah.http.httpsclient.MyHttpsClient;
import com.ah.http.httpsclient.constants.HttpHeaderContentTypeEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tao on 2019/12/6
 */
public class HttpsDemo {
    public static void main(String[] args) throws Exception {
//        httpsGet();
        httpsPost();
//        httpGet();
//        httpPost();

    }
    public static String httpsGet1() throws Exception {
        String url = "https://192.168.53.201/api/getMenuList";

        //参数
        Map<String, Object> paramsMap = new HashMap<String, Object>();
//        paramsMap.put("username", "admin");
//        paramsMap.put("password", "9c16ff1ecec9195cf8d30bec799d31ec5e09dda0");

        //消息头
        Map<String, String> headersMap = new HashMap<String, String>();
//        headersMap.put("Referer", "https://192.168.30.194/index.html");

        //get请求
        Object result = MyHttpsClient.sendGetHttps(url, paramsMap, headersMap);

        System.out.println("httpsGet返回信息：" + result);
        return result.toString();
    }

    public static String httpsGet() throws Exception {
        String url = "https://192.168.53.201/api/getMenuList";

        //参数
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("username", "admin");
        paramsMap.put("password", "9c16ff1ecec9195cf8d30bec799d31ec5e09dda0");

        //消息头
        Map<String, String> headersMap = new HashMap<String, String>();
        headersMap.put("Referer", "https://192.168.53.201/index.html");

        //get请求
        Object result = MyHttpsClient.sendGetHttps(url, paramsMap, headersMap);

        System.out.println("httpsGet返回信息：" + result);
        return result.toString();
    }

    public static String httpsPost() throws Exception {
        String url = "https://192.168.53.201/api/login";

        //参数
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("username", "admin");
        paramsMap.put("password", "9c16ff1ecec9195cf8d30bec799d31ec5e09dda0");

        //消息头
        Map<String, String> headersMap = new HashMap<String, String>();
        headersMap.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        headersMap.put("Cookie", "JSESSIONID=1");
        headersMap.put("Referer", "https://192.168.53.201/index.html");

        //post请求
        Object result2 = MyHttpsClient.sendPostHttps(url, paramsMap, headersMap, HttpHeaderContentTypeEnum.X_WWW_FORM.getKey());

        System.out.println("httpsPost返回信息：" + result2);
        System.out.println("httpsPost返回信息：" + result2.toString());
        return result2.toString();
    }

}
